package org.yoao.crm.business.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.yoao.crm.bean.Nac;
import org.yoao.crm.business.service.INacService;
import org.yoao.crm.dao.NacDAO;
import org.yoao.crm.struts.form.NacForm;
import org.yoao.crm.tools.TimeTool;

/**
 * @author yxwonline.com
 * @description 
 * @date 2010-9-8 下午04:23:29
 */
public class NacServiceImpl implements INacService {
	private NacDAO dao = new NacDAO();
	
	@Override
	public boolean add(NacForm form, String tableName) throws Exception {
		Nac bean = new Nac();
		BeanUtils.copyProperties(bean, form);
		bean.setTableName(tableName);
		bean.setCreateTime(TimeTool.getSystemTime());
		if(dao.insert(bean) > -1) return true;
		else return false;
	}

	@Override
	public boolean delete(String id, String tableName) throws Exception {
		dao.delete(id, tableName);
		return true;
	}

	@Override
	public int getDataCount(Map map) throws Exception {
		return dao.getDataCount(map);
	}

	@Override
	public List view(int startRow, int endRow, Map map) throws Exception {
		return dao.find(startRow, endRow, map);
	}
	
	public void signature(String tableName, String id, String value) throws Exception {
		if(id.endsWith(",")) id = id.substring(0, id.length()-1);
		dao.modifyIsFlag(tableName, id, value);
	}

	@Override
	public boolean modify(String tableName, String id, String memo)
			throws Exception {
		Nac bean = new Nac();
		bean.setTableName(tableName);
		bean.setId(Integer.parseInt(id));
		bean.setMemo(memo);
		if(dao.modifyMemo(bean) > -1)
			return true;
		else return false;
	}
}
